package com.zwy.springinner.listener;

import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Service;

@Service
public class MqttMessageListener {

    // 监听 mqttInputChannel 并处理消息
    @ServiceActivator(inputChannel = "mqttInputChannel")
    public void handleMessage(Message<?> message) {
        String payload = message.getPayload().toString();
        String topic = message.getHeaders().get("mqtt_receivedTopic").toString();
        System.out.println("Received message from topic: " + topic);
        System.out.println("Message payload: " + payload);
    }
}
